<?php
namespace api\modules\v1\controllers;

use api\components\ApiController;
use api\modules\v1\models\Need;
use Yii;

/**
 *
 * @author ZCY
 */
class NeedController extends ApiController
{
    /**
     * 发布买入广告
     * @author ZCY
     */
    public function actionBuy()
    {
        $params = Yii::$app->request->post();
        $model = new Need();
        $model->setScenario(Need::SCENARIO_BUY);
        $model->load($params, '');
        if ($result = $model->buy()) {
            return ['message' => '发布购买广告成功', 'data' => $result];
        }
    }

    /**
     * 发布卖出广告
     * @author ZCY
     */
    public function actionSell()
    {
        $params = Yii::$app->request->post();
        $model = new Need();
        $model->setScenario(Need::SCENARIO_SELL);
        $model->load($params, '');
        if ($result = $model->sell()) {
            return ['message' => '发布卖出广告成功', 'data' => $result];
        }
    }

    /**
     * 需求列表
     */
    public function actionList()
    {
        $params = Yii::$app->request->post();
        $model = new Need();
        $model->setScenario(Need::SCENARIO_LIST);
        $model->load($params, '');
        if ($result = $model->needlist()) {
            return ['message' => '广告列表获取成功', 'data' => $result];
        }
    }

    /**
     * 需求详情
     */
    public function actionInfo()
    {
        $params = Yii::$app->request->post();
        $model = new Need();
        $model->setScenario(Need::SCENARIO_INFO);
        $model->load($params, '');
        if ($result = $model->needinfo()) {
            return ['message' => '广告详情获取成功', 'data' => $result];
        }
    }

}
